package fhp.hlhj.giantfold.activity.partner

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.adapter.MyFansFgmAdp
import fhp.hlhj.giantfold.fragment.MyFansFgm
import kotlinx.android.synthetic.main.activity_my_fans_aty.*

class MyFansAty : BaseActivity(), ViewPager.OnPageChangeListener, TabLayout.OnTabSelectedListener {
    private lateinit var viewPagerAdp:MyFansFgmAdp
    private  var fgm1:MyFansFgm = MyFansFgm()
    private  var fgm2:MyFansFgm=MyFansFgm()
    override fun getContentId(): Int = R.layout.activity_my_fans_aty
    override fun initView() {
        val fgms=ArrayList<Fragment>()
        fgms.add(fgm1)
        fgms.add(fgm2)
        viewPagerAdp=MyFansFgmAdp(supportFragmentManager,fgms)
        viewPager.adapter=viewPagerAdp

        viewPager.addOnPageChangeListener(this)
        tabLayout.addOnTabSelectedListener(this)
    }
    /**
     * ViewPager监听
     */
    override fun onPageScrollStateChanged(state: Int) {
    }
    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
    }
    override fun onPageSelected(position: Int) {
        tabLayout.getTabAt(position)!!.select()
    }

    /**
     * TabLayout监听
     */
    override fun onTabReselected(tab: TabLayout.Tab?) {
    }
    override fun onTabUnselected(tab: TabLayout.Tab?) {
    }
    override fun onTabSelected(tab: TabLayout.Tab) {
        viewPager.currentItem = tab.position%2
    }

}
